package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Show;
import org.akomantoso.core.data.attribute.Value;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;

/**
 * The element keyword is a metadata element specifying a keyword associated to the FRBR expression of the document.
 * Attribute dictionary (required) specifies the thesaurus out of which the keyword has been taken.
 * 
 * <pre>
 * 	<xsd:element name="keyword">
 * 		<xsd:complexType>
 * 			<xsd:complexContent>
 * 				<xsd:extension base="metaopt">
 * 					<xsd:attributeGroup ref="value"/>
 * 					<xsd:attributeGroup ref="show"/>
 * 					<xsd:attribute name="dictionary" type="xsd:anyURI" use="required"/>
 * 				</xsd:extension>
 * 			</xsd:complexContent>
 * 		</xsd:complexType>
 * 	</xsd:element>
 * </pre>
 * 
 */
public final class Keyword extends MetaOpt implements Value,Show{

	public static final String ELEMENT = "keyword";
	
	public static final String ATTRIBUTE_DICTIONARY = "dictionary";
	
	// Mandatory
	private String _showAs;
	
	// Optional
	private String _shortForm;
	
	// Mandatory
	private String _value;
	
	// Mandatory
	private String _dictionary;
	
	
	/**
	 * @see org.akomantoso.core.data.attribute.Show#getShowAs()
	 */
	@Override
	public String getShowAs() {
		return _showAs;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Show#setShowAs(java.lang.String)
	 */
	@Override
	public void setShowAs(String showAs) {
		_showAs = showAs;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Show#getShortForm()
	 */
	@Override
	public String getShortForm() {
		return _shortForm;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Show#setShortForm(java.lang.String)
	 */
	@Override
	public void setShortForm(String shortForm) {
		_shortForm = shortForm;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Value#getValue()
	 */
	@Override
	public String getValue() {
		return _value;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Value#setValue(java.lang.String)
	 */
	@Override
	public void setValue(String value) {
		_value = value;
	}
	
	public String getDictionary() {
		return _dictionary;
	}

	public void setDictionary(String dictionary) {
		_dictionary = dictionary;
	}

	/**
	 * @see org.akomantoso.core.data.MetaOpt#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeShow(out, this);
		OutputUtil.writeValue(out, this);
		OutputUtil.writeMandatoryAttribute(out, ATTRIBUTE_DICTIONARY, _dictionary, this);
		super.writeExternal(out);
		out.writeEnd();
	}

	/**
	 * @see org.akomantoso.core.data.MetaOpt#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {

		// Mandatory
		_showAs = in.readAttribute(Show.ATTRIBUTE_SHOW_AS);
		_shortForm = in.readAttribute(Show.ATTRIBUTE_SHORT_FORM);
		_value = in.readAttribute(Value.ATTRIBUTE);
		_dictionary = in.readAttribute(ATTRIBUTE_DICTIONARY);
		
		// Optional
		super.readExternal(in);
	}
	
	

	
}
